<!DOCTYPE html>
<html>

{include file='public/header'}

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">投手管理</a>
            <a><cite>账号管理</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-inline">
                    <label class="layui-form-label w-auto">投手名称：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" placeholder="请输入投手名称" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <button class="layui-btn" style="margin-left: 10px;" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </form>
        </div>
        <table id="pitcher" lay-filter="pitcher"></table>
    </div>
    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
        </div>
    </script>
    <script type="text/html" id="tbBar">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    </script>
    <script type="text/html" id="switchTpl">
        <input type="checkbox"  name="sex" value="{{d.id}}" lay-skin="switch" lay-text="在职|离职" lay-filter="sexDemo" {{ d.is_depart == 0 ? 'checked' : '' }}>
    </script>
    <script>
        let params = {
            elem: '#pitcher'
            , toolbar: '#toolbar'
            , url: '/cps/pitcher/list' //数据接口
            , id: 'pitcher'
            , page:true
            , limit:15
            , cols: [[ //表头
                { field: 'id', title: 'ID', width: 70, sort: true, align:'center' }
                , { field: 'name', title: '名称', align:'center' }
                , { field: 'official_account_name', title: '可投放小程序/公众号', align:'center' }
                , { field: 'is_depart', title: '状态', width: 200, templet: '#switchTpl', unresize: true, align: 'center'}
                , { toolbar: '#tbBar', title: '操作', align: 'center', width: 200}
            ]]
        }
        tableList(params)

        layui.use('table', function () {
            var table = layui.table;
            table.on('toolbar(pitcher)', function (obj) {
                var event = obj.event;
                if (event === 'add') {
                    x_admin_show('添加', './info.html', 650, 500);
                }
            });
            table.on('tool(pitcher)', function (obj) {
                var event = obj.event;
                if (event === 'edit') {
                    x_admin_show('编辑', `./info.html?id=${obj.data.id}`, 650, 500);
                }
            });
            form.on('switch(sexDemo)', function (obj) { // 根据业务判断是开启还是关闭
                let getRechargeType = new Promise((resolve) => {
                    Ajax('/cps/pitcher/departStatus', {id:this.value,is_depart:obj.elem.checked?0:1}).then(result => {
                        resolve(result.data)
                        if(result.code===200){
                            layer.msg('修改成功!');
                        }
                    });
                })
            });
        });
        

    </script>
</body>

</html>